<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 5.4.2">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.1.1/css/all.min.css" integrity="sha256-DfWjNxDkM94fVBWx1H5BMMp0Zq7luBlV8QRcSES7s+0=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/pace-js@1.2.4/themes/blue/pace-theme-center-circle.css">
  <script src="https://cdn.jsdelivr.net/npm/pace-js@1.2.4/pace.min.js" integrity="sha256-gqd7YTjg/BtfqWSwsJOvndl0Bxc8gFImLEkXQT8+qj0=" crossorigin="anonymous"></script>

<script class="next-config" data-name="main" type="application/json">{"hostname":"gitee.com","root":"/","images":"/images","scheme":"Gemini","darkmode":false,"version":"8.11.1","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":false,"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="1-安装插件">
<meta property="og:type" content="article">
<meta property="og:title" content="vue2-axios-使用echarts">
<meta property="og:url" content="https://gitee.com/zj-jjjz/cleanyourmind.git/2022/11/27/vue2-axios-%E4%BD%BF%E7%94%A8echarts/index.html">
<meta property="og:site_name" content="做技术要静下心来">
<meta property="og:description" content="1-安装插件">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2022-11-27T09:17:12.000Z">
<meta property="article:modified_time" content="2022-11-27T11:47:17.000Z">
<meta property="article:author" content="戒骄戒躁">
<meta property="article:tag" content="vue2">
<meta property="article:tag" content="echarts">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="https://gitee.com/zj-jjjz/cleanyourmind.git/2022/11/27/vue2-axios-%E4%BD%BF%E7%94%A8echarts/">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://gitee.com/zj-jjjz/cleanyourmind.git/2022/11/27/vue2-axios-%E4%BD%BF%E7%94%A8echarts/","path":"2022/11/27/vue2-axios-使用echarts/","title":"vue2-axios-使用echarts"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>vue2-axios-使用echarts | 做技术要静下心来</title>
  





  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">做技术要静下心来</p>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E5%AE%89%E8%A3%85%E6%8F%92%E4%BB%B6"><span class="nav-number">1.</span> <span class="nav-text">1-安装插件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E5%BC%95%E5%85%A5%E6%8F%92%E4%BB%B6"><span class="nav-number">2.</span> <span class="nav-text">2-引入插件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E4%BD%BF%E7%94%A8Echarts%E7%BB%84%E4%BB%B6"><span class="nav-number">3.</span> <span class="nav-text">3-使用Echarts组件</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%A8%A1%E7%89%88%E4%B8%AD%E4%BD%BF%E7%94%A8Echarts%EF%BC%8C%E5%B9%B6%E8%AE%BE%E7%BD%AE%E9%AB%98%E5%BA%A6"><span class="nav-number">3.1.</span> <span class="nav-text">模版中使用Echarts，并设置高度</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%BE%E7%BD%AEdata%E5%92%8C%E8%AE%A1%E7%AE%97%E5%B1%9E%E6%80%A7option"><span class="nav-number">3.2.</span> <span class="nav-text">设置data和计算属性option</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AF%B7%E6%B1%82%E6%95%B0%E6%8D%AE"><span class="nav-number">3.3.</span> <span class="nav-text">请求数据</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%9C%A8%E9%A1%B5%E9%9D%A2%E5%88%9D%E5%A7%8B%E5%8C%96%E5%90%8E%E8%B0%83%E7%94%A8%E5%87%BD%E6%95%B0"><span class="nav-number">3.4.</span> <span class="nav-text">在页面初始化后调用函数</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%94%B9%E5%8F%98option%E4%B8%AD%E7%9A%84data"><span class="nav-number">3.5.</span> <span class="nav-text">改变option中的data</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E6%80%BB%E7%BB%93"><span class="nav-number">4.</span> <span class="nav-text">4-总结</span></a></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="戒骄戒躁"
      src="/images/avatar.gif">
  <p class="site-author-name" itemprop="name">戒骄戒躁</p>
  <div class="site-description" itemprop="description">前端基础知识分享</div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">3</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">2</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">5</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author site-overview-item animated">
      <span class="links-of-author-item">
        <a href="https://github.com/yourname" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;yourname" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:yourname@gmail.com" title="E-Mail → mailto:yourname@gmail.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
  </div>



        </div>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://gitee.com/zj-jjjz/cleanyourmind.git/2022/11/27/vue2-axios-%E4%BD%BF%E7%94%A8echarts/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="戒骄戒躁">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="做技术要静下心来">
      <meta itemprop="description" content="前端基础知识分享">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="vue2-axios-使用echarts | 做技术要静下心来">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          vue2-axios-使用echarts
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>
      

      <time title="创建时间：2022-11-27 17:17:12 / 修改时间：19:47:17" itemprop="dateCreated datePublished" datetime="2022-11-27T17:17:12+08:00">2022-11-27</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98/" itemprop="url" rel="index"><span itemprop="name">项目实战</span></a>
        </span>
    </span>

  
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>428</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>2 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <h2 id="1-安装插件"><a href="#1-安装插件" class="headerlink" title="1-安装插件"></a>1-安装插件</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">npm install echarts vue-echarts   这是两个插件</span><br><span class="line">npm install axios --save</span><br></pre></td></tr></table></figure>



<h2 id="2-引入插件"><a href="#2-引入插件" class="headerlink" title="2-引入插件"></a>2-引入插件</h2><p>在main.js中，</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 全局引入echarts</span></span><br><span class="line"><span class="keyword">import</span> <span class="string">&#x27;echarts&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="title class_">ECharts</span> <span class="keyword">from</span> <span class="string">&#x27;vue-echarts&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 全局引入axios，配置默认地址，并挂载到vue对象的原型上</span></span><br><span class="line"><span class="keyword">import</span> axios <span class="keyword">from</span> <span class="string">&#x27;axios&#x27;</span></span><br><span class="line">axios.<span class="property">defaults</span>.<span class="property">baseURL</span> = <span class="string">&#x27;http://localhost:8888&#x27;</span></span><br><span class="line"><span class="title class_">Vue</span>.<span class="property"><span class="keyword">prototype</span></span>.<span class="property">$axios</span> = axios</span><br><span class="line"></span><br><span class="line"><span class="comment">// 注册全局组件 ECharts</span></span><br><span class="line"><span class="title class_">Vue</span>.<span class="title function_">component</span>(<span class="string">&#x27;ECharts&#x27;</span>, <span class="title class_">ECharts</span>)</span><br></pre></td></tr></table></figure>

<h2 id="3-使用Echarts组件"><a href="#3-使用Echarts组件" class="headerlink" title="3-使用Echarts组件"></a>3-使用Echarts组件</h2><h3 id="模版中使用Echarts，并设置高度"><a href="#模版中使用Echarts，并设置高度" class="headerlink" title="模版中使用Echarts，并设置高度"></a>模版中使用Echarts，并设置高度</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">&lt;template&gt;</span><br><span class="line">  &lt;div&gt;</span><br><span class="line">    &lt;!-- 图表的容器 --&gt;</span><br><span class="line">    &lt;ECharts class=&quot;chart&quot; :option=&quot;option&quot;&gt;&lt;/ECharts&gt;</span><br><span class="line">  &lt;/div&gt;</span><br><span class="line">&lt;/template&gt;</span><br><span class="line"></span><br><span class="line">// 一定要设置高度！！！</span><br><span class="line">&lt;style lang=&#x27;less&#x27; scoped&gt;</span><br><span class="line">.chart &#123;</span><br><span class="line">  height: 500px;</span><br><span class="line">&#125;</span><br><span class="line">&lt;/style&gt;</span><br></pre></td></tr></table></figure>

<h3 id="设置data和计算属性option"><a href="#设置data和计算属性option" class="headerlink" title="设置data和计算属性option"></a>设置data和计算属性option</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">&lt;script&gt;</span><br><span class="line">    export default &#123;</span><br><span class="line">        data() &#123;</span><br><span class="line">            return &#123; data:[] &#125;</span><br><span class="line">		&#125;,</span><br><span class="line">        computed:&#123;</span><br><span class="line">            option() &#123;</span><br><span class="line">                return &#123;</span><br><span class="line">                    	xAxis: &#123;</span><br><span class="line">  							type: &quot;category&quot;,</span><br><span class="line">  							data: [2,4,6,7,8],</span><br><span class="line">						&#125;,</span><br><span class="line">						yAxis: &#123;</span><br><span class="line">  							type: &quot;value&quot;,</span><br><span class="line">						&#125;,</span><br><span class="line">						series: [</span><br><span class="line">  							&#123;</span><br><span class="line">                                data: [1000,2000,3000,4000,5000],</span><br><span class="line">                                type: &quot;line&quot;,</span><br><span class="line">  							&#125;,</span><br><span class="line">						],</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&lt;/script&gt;    </span><br></pre></td></tr></table></figure>

<h3 id="请求数据"><a href="#请求数据" class="headerlink" title="请求数据"></a>请求数据</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">&lt;script&gt;</span><br><span class="line">    export default &#123;</span><br><span class="line">       methods: &#123;</span><br><span class="line">        // 异步请求数据，并赋值给data</span><br><span class="line">        async getDate() &#123;</span><br><span class="line">          this.data = await this.$axios(&#123; url: &quot;/data&quot; &#125;);</span><br><span class="line">        &#125;,</span><br><span class="line">     &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&lt;/script&gt;     </span><br></pre></td></tr></table></figure>

<p><strong>后端请求回来的数据为</strong></p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">[</span></span><br><span class="line">       <span class="punctuation">&#123;</span> <span class="attr">&quot;time&quot;</span><span class="punctuation">:</span> <span class="string">&quot;2019&quot;</span><span class="punctuation">,</span> <span class="attr">&quot;value&quot;</span><span class="punctuation">:</span> <span class="number">100</span> <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">       <span class="punctuation">&#123;</span> <span class="attr">&quot;time&quot;</span><span class="punctuation">:</span> <span class="string">&quot;2020&quot;</span><span class="punctuation">,</span> <span class="attr">&quot;value&quot;</span><span class="punctuation">:</span> <span class="number">200</span> <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">       <span class="punctuation">&#123;</span> <span class="attr">&quot;time&quot;</span><span class="punctuation">:</span> <span class="string">&quot;2021&quot;</span><span class="punctuation">,</span> <span class="attr">&quot;value&quot;</span><span class="punctuation">:</span> <span class="number">300</span> <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">       <span class="punctuation">&#123;</span> <span class="attr">&quot;time&quot;</span><span class="punctuation">:</span> <span class="string">&quot;2022&quot;</span><span class="punctuation">,</span> <span class="attr">&quot;value&quot;</span><span class="punctuation">:</span> <span class="number">400</span> <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">     <span class="punctuation">]</span></span><br></pre></td></tr></table></figure>

<h3 id="在页面初始化后调用函数"><a href="#在页面初始化后调用函数" class="headerlink" title="在页面初始化后调用函数"></a>在页面初始化后调用函数</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">&lt;script&gt;</span><br><span class="line">    export default &#123;</span><br><span class="line">        mounted() &#123;</span><br><span class="line">            this.getState()</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&lt;/script&gt;   </span><br></pre></td></tr></table></figure>

<h3 id="改变option中的data"><a href="#改变option中的data" class="headerlink" title="改变option中的data"></a>改变option中的data</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">&lt;script&gt;</span><br><span class="line">    export default &#123;</span><br><span class="line">        data() &#123;</span><br><span class="line">            return &#123; data:[] &#125;</span><br><span class="line">		&#125;,</span><br><span class="line">        computed:&#123;</span><br><span class="line">            option() &#123;</span><br><span class="line">                return &#123;</span><br><span class="line">                    	xAxis: &#123;</span><br><span class="line">  							type: &quot;category&quot;,</span><br><span class="line">                            // 因为option中的data应为数组,所以通过map把返回的数据改成数组</span><br><span class="line">  		/*修改了这一行*/		data: this.data.map(item =&gt; item.time),     </span><br><span class="line">						&#125;,</span><br><span class="line">						yAxis: &#123;</span><br><span class="line">  							type: &quot;value&quot;,</span><br><span class="line">						&#125;,</span><br><span class="line">						series: [</span><br><span class="line">  							&#123;</span><br><span class="line">                                // 因为option中的data应为数组,所以通过map把返回的数据改成数组</span><br><span class="line">           /*修改了这一行*/       data: this.data.map(item =&gt; item.value),,</span><br><span class="line">                                type: &quot;line&quot;,</span><br><span class="line">  							&#125;,</span><br><span class="line">						],</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&lt;/script&gt;    </span><br></pre></td></tr></table></figure>





<h2 id="4-总结"><a href="#4-总结" class="headerlink" title="4-总结"></a>4-总结</h2><p>在vue2中使用Echarts，分七步</p>
<ol>
<li>模版中引用组件</li>
<li>设置高度</li>
<li>设置data，存放请求回来的数据</li>
<li>设置computed，用来返回option</li>
<li>请求函数的方法</li>
<li>mounted中调用方法</li>
<li>把option中静态数据换成请求回来的数据</li>
</ol>
<p>这样一个简单的 Echarts 图就弄好了</p>

    </div>

    
    
    

    <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/vue2/" rel="tag"># vue2</a>
              <a href="/tags/echarts/" rel="tag"># echarts</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/2022/11/22/%E8%B0%88%E8%B0%88%E4%BD%A0%E5%AF%B9%E9%97%AD%E5%8C%85%E7%9A%84%E7%90%86%E8%A7%A3/" rel="prev" title="谈谈你对闭包的理解">
                  <i class="fa fa-chevron-left"></i> 谈谈你对闭包的理解
                </a>
            </div>
            <div class="post-nav-item">
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">戒骄戒躁</span>
</div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
    <span title="站点总字数">1k</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">4 分钟</span>
  </span>
</div>

<!--
  <div class="powered-by">由 <a href="https://hexo.io/" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div> -->

    </div>
  </footer>

  
  <script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script>

  
<script src="https://cdn.jsdelivr.net/npm/hexo-generator-searchdb@1.4.0/dist/search.js" integrity="sha256-vXZMYLEqsROAXkEw93GGIvaB2ab+QW6w3+1ahD9nXXA=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>




  <script src="/js/third-party/pace.js"></script>

  





</body>
</html>
